﻿using Sys.Core;
using Sys.Core.Models.Dto;
using Sys.Core.Models.Queries;
using Sys.Core.Models.VO;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Web;
using MiniFox.Utility;
using MiniFox.Web.Filters;
using MiniFox.Web.Infrastructure;

namespace Sys.Controllers
{
    [NoCache, ValidationFilter, Area(GlobalConstants.AREA_NAME)]
    public class RoleController : AuthorizedController<IRoleService>
    {
        [HttpPost]
        public Response<ResultObject<IEnumerable<RoleVo>>> Query([FromBody] PagedQueryObject<RoleQuery> request)
        {
            var result = this.Component.Query(request);
            return result.CreateResponse();
        }

        [HttpGet]
        public Response<RoleVo> Item([FromQuery] string id)
        {
            RoleVo role = this.Component.Item(id);
            return role.CreateResponse();
        }

        [HttpPost]
        public Response<RoleVo> Create([FromBody] RoleDto role)
        {
            var result = this.Component.Create(role);

            return result.CreateResponse();
        }

        [HttpPost]
        public Response<RoleVo> Update([FromBody] RoleDto role)
        {
            var result = this.Component.Update(role);

            return result.CreateResponse();
        }

        [HttpPost]
        public Response<string> Delete([FromBody] string data)
        {
            var result = this.Component.Delete(data);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<ResultObject<IEnumerable<UserVo>>> InclusionUsers([FromQuery] string roleId, [FromBody] PagedQueryObject<UserQuery> request)
        {
            var result = this.Component.InclusionUsers(roleId, request);
            return result.CreateResponse();
        }
        [HttpPost]
        public Response<ResultObject<IEnumerable<UserVo>>> ExclusionUsers([FromQuery] string roleId, [FromBody] PagedQueryObject<UserQuery> request)
        {
            var result = this.Component.ExclusionUsers(roleId, request);
            return result.CreateResponse();
        }
        [HttpPost]
        public Response AddUsers([FromBody] RoleUserSet roleUserSet)
        {
            var result = this.Component.AddRoleUsers(roleUserSet); 
            return result.CreateResponse();
        }
        [HttpPost]
        public Response RemoveUsers([FromBody] RoleUserSet roleUserSet)
        {
            var result = this.Component.RemoveRoleUsers(roleUserSet);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<ResultObject<IEnumerable<ModuleVo>>> InclusionModules([FromQuery] string roleId, [FromBody] PagedQueryObject<ModuleQuery> request)
        {
            var result = this.Component.InclusionModules(roleId, request);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<ResultObject<IEnumerable<ModuleVo>>> ExclusionModules([FromQuery] string roleId, [FromBody] PagedQueryObject<ModuleQuery> request)
        {
            var result = this.Component.ExclusionModules(roleId, request);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response AddModules([FromBody] RoleModuleSet request)
        {
            var result = this.Component.AddRoleModules(request);
            return result.CreateResponse();
        }
        [HttpPost]
        public Response RemoveModules([FromBody] RoleModuleSet request)
        {
            var result = this.Component.RemoveRoleModules(request);
            return result.CreateResponse();
        }

    }
}
